<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改村民购煤订单')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <h2>集中购煤系统</h2>
    <form class="form-horizontal m" id="form-clientUserorder-edit" th:object="${clientUserOrder}">
        <div class="form-group">
            <label class="col-sm-3 control-label">
                <span th:text="'本批次购煤数量：'+${sumOrder?.amount == null ? '0' : sumOrder?.amount}+'吨'"></span>
            </label>
            <label class="col-sm-3 control-label">
                <span th:text="'已付购煤款：'+${sumOrder?.money == null ? '0' : sumOrder?.money}+'元'"></span>
            </label>
            <input type="hidden" name="amount" id="amount" th:value="${sumOrder?.amount == null ? '0' : sumOrder?.amount}">
            <input type="hidden" name="money" th:value="${sumOrder?.money == null ? '0' : sumOrder?.money}">
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">供应商选择：</label>
            <div class="col-sm-5">
                <select class="form-control" name="supplierId" id="supplier-select" required>
                    <option value="">请选择</option>
                    <option th:each="supplier : ${supplierList}" th:value="${supplier.id}" th:text="${supplier.name }" th:attr="data-qrcode=${supplier.qrCode}">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-5" id="qrcode">
            </div>
        </div>
    </form>

    <div class="box-footer">
        <div class="col-sm-offset-5 col-sm-6">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>提交订单</button>&nbsp;
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "jjm/clientUserorder";
    console.log(ctx);
    $("#form-clientUserorder-edit").validate({
        focusCleanup: true
    });

    $("#supplier-select").on("change",function () {
        var qrcode = $(this).find("option:selected").data("qrcode");
        if(!qrcode){
            $("#qrcode").html("");
        }else{
            $("#qrcode").html('<img width="300" height="300" src="'+qrcode+'"/>')
        }
    })

    function submitHandler() {
        if ($.validate.form()) {
            var amount = $("#amount").val();
            if(!amount || amount == 0){
                $.modal.alertWarning("本批次暂未购煤");
            }
            $.operate.save("/jjm/order/add", $('#form-clientUserorder-edit').serialize());
        }
    }

</script>
</body>
</html>